package com.ruoyi.car.controller.part;

import com.car.pojo.TPartBatteryPackInformation;
import com.car.pojo.TPartBatteryPackModel;
import com.car.pojo.TPartBatteryPackModelValue;
import com.car.pojo.TPartPatternAssembly;
import com.ruoyi.car.service.BatteryPackageService;
import com.ruoyi.car.service.BatteryServiceinter;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.framework.web.domain.server.Sys;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/cpart/packege")
public class BatteryPackageController extends BaseController {
    String prefix="/car/cpart";
    @Autowired
    private BatteryPackageService batteryPackageService;
//    @Autowired
//    private BatteryServiceinter batteryServiceinter;
    //页面初始跳转
    @RequiresPermissions("cpart:batterypackage:vidio")
    @GetMapping()
    public String batterypackage()
    {
        return prefix + "/batterypackage";
    }

    @RequiresPermissions("cpart:batterypackage:model")
    @GetMapping("/model")
    public String batterypackagemodel()
    {
        return prefix + "/batterypackagemodel";
    }


    //电池包信息列表
    @RequiresPermissions("cpart:batterypackage:batterypackagelist")
    @PostMapping("/batterypackagelist")
    @ResponseBody
    public TableDataInfo batterypackagelist(Map map){

        System.out.println(map.get("batteryBagModelName"));
        startPage();
        List<TPartBatteryPackInformation> allTPartBatteryPackInformation = batteryPackageService.findAllTPartBatteryPackInformation(map);
        //model.addAttribute("battery",allpatternAssmbly);
        return getDataTable(allTPartBatteryPackInformation);
    }
    /**
     * 添加电池包信息
     */
    @GetMapping("/addbatterypackage")
    public String add()
    {
        return prefix + "/addbatterypackage";
    }
    @RequiresPermissions("cpart:batterypackage:addbatterypackage")
    @Log(title = "电池包信息", businessType = BusinessType.INSERT)
    @PostMapping("/addbatterypackage")
    @ResponseBody
    public AjaxResult addSave(TPartBatteryPackInformation tPartPatternAssembly)
    {
        return toAjax(batteryPackageService.addInformation(tPartPatternAssembly));
    }
    /**
     * 修改电池包信息
     */
    //回显
    @GetMapping("/editbatterypackage/{pbid}")
    public String edit(@PathVariable("pbid") String pbid, ModelMap mmap)
    {
        TPartBatteryPackInformation tPartBatteryPackInformation = batteryPackageService.selectTPartBatteryPackInformationById(pbid);

        mmap.put("tPartBatteryPackInformation", tPartBatteryPackInformation);
        return prefix + "/editbatterypackage";
    }
    //修改
    @RequiresPermissions("cpart:batterypackage:editbatterypackage")
    @Log(title = "电池包信息", businessType = BusinessType.UPDATE)
    @PostMapping("/editbatterypackage")
    @ResponseBody
    public AjaxResult editbatterypackage(TPartBatteryPackInformation tPartBatteryPackInformation)
    {
        return toAjax(batteryPackageService.updateTPartBatteryPackInformation(tPartBatteryPackInformation));
    }
    /**
     * 删除电池包信息
     */
    @RequiresPermissions("cpart:batterypackage:removebatterypackage")
    @Log(title = "电池模组信息", businessType = BusinessType.DELETE)
    @PostMapping( "/removebatterypackage")
    @ResponseBody
    public AjaxResult removebatterypackage(String ids)
    {
        return toAjax(batteryPackageService.deleteTPartBatteryPackInformationByIds(ids));
    }


    //电池包型号列表
    @RequiresPermissions("cpart:batterypackage:batterypackagemodellist")
    @PostMapping("/batterypackagemodellist")
    @ResponseBody
    public TableDataInfo batterypackagemodellist(TPartBatteryPackModel tPartBatteryPackModel){

        //System.out.println(map.get("batteryBagModelName"));
        startPage();
        List<TPartBatteryPackModel> allTPartBatteryPackModel = batteryPackageService.findAllTPartBatteryPackModel(tPartBatteryPackModel);
        //model.addAttribute("battery",allpatternAssmbly);
        return getDataTable(allTPartBatteryPackModel);
    }
    //查看详细参数
    @GetMapping("/svalue/{id}")
    public String svalue(@PathVariable("id") String id, ModelMap mmap)
    {
        TPartBatteryPackModel tPartBatteryPackModel = batteryPackageService.selectTPartBatteryPackModelById(id);
        mmap.put("tPartBatteryPackModel", tPartBatteryPackModel);
        return prefix + "/svaluepackagemodel";
    }
    //查看电池模组详细参数
    @GetMapping("/findgroup/{id}")
    public String findgroup(@PathVariable("id") String id, ModelMap mmap)
    {
        List<TPartBatteryPackModelValue> ll =  batteryPackageService.findAllGroupInterfaceOfPackage(id);
        mmap.put("tPartBatteryPackModelValueList", ll);
        return prefix + "/tPartBatteryPackModelValueList";
    }

    /**
     * 添加电池包型号
     */
    @GetMapping("/addbatterypackagemodel")
    public String addmodel()
    {
        return prefix + "/addbatterypackagemodel";
    }
    @RequiresPermissions("cpart:batterypackage:addbatterypackagemodel")
    @Log(title = "电池包型号", businessType = BusinessType.INSERT)
    @PostMapping("/addbatterypackagemodel")
    @ResponseBody
    public AjaxResult addSavemodel(TPartBatteryPackModel tPartBatteryPackModel)
    {

        return toAjax(batteryPackageService.addTPartBatteryPackModel(tPartBatteryPackModel));
    }
    /**
     * 删除电池包型号
     */
    @RequiresPermissions("cpart:batterypackage:removebatterypackagemodel")
    @Log(title = "电池包型号", businessType = BusinessType.DELETE)
    @PostMapping( "/removebatterypackagemodel")
    @ResponseBody
    public AjaxResult removebatterypackagemodel(String ids)
    {
        return toAjax(batteryPackageService.deleteTPartBatteryPackModelByIds(ids));
    }







}
